<?php
/**
 * Break
 *
 * 'break' ends execution of the current 'for', 'foreach', 'while', 'do-while'
 * or 'switch' structure.
 *
 * 'break' accepts an optional numeric argument which tells it how many
 * nested enclosing structures are to be broken out of.
 *
 * @author  Badrus Said <badrus.said@gmail.com>
 * @since   gop1.0
 */
final class gop_Break extends gop_Base {
    public function execute(gop_Base $_caller = null) {
        if ($this->getReturn()) return;
        $this->setCaller($_caller);
        $caller = $this->getCaller();
        while($caller) {
            if ($caller instanceof gop_BaseIterator) {
                $B = (int)$this->nestedLevel;
                $caller->interupt(1, ($this->getContext()->hasCallee($B)) ? $this->getContext()->getCallee($B)->execute() : $B);
                break;
            }
            $caller = $caller->getCaller();
        }
    }
}
?>